<script setup lang="ts">
import { ElMessage } from "element-plus";
import { removeToken, removeUser } from '../../../utils/session'
import { useRouter } from 'vue-router'
import config from '../../../config'
import { ref } from "vue"

defineProps({
  userName: String
})
const router = useRouter()
const adminTitle = ref(config.adminTitle)

const logout = async () => {
  await removeToken()
  await removeUser()
  ElMessage({
    type: 'success',
    message: '注销成功'
  })
  await router.push({path: '/login'})
}
</script>

<template>
  <div class="container">
    <h2 class="title">{{adminTitle}}</h2>
    <div class="userInfo">
      <el-popover
          placement="bottom"
          :width="100"
          trigger="click"
      >
        <template #reference>
          <span>{{userName}}</span>
        </template>
        <div class="opBox" style="cursor: pointer" @click="logout">
          <span>注销</span>
        </div>
      </el-popover>
    </div>
  </div>
</template>

<style lang="less" scoped>
.container {
  width: 100%;
  height: 100%;
  border-bottom: 1px solid #e0e0e0;
  background-color: @GlobalColor;
  justify-content: space-between;
  display: flex;
  align-items: center;
  .title {
    font-size: 17px;
    margin-left: 30px;
    color: #fff;
  }
  .userInfo {
    margin-right: 20px;
    color: #fff;
    font-size: 14px;
    cursor: pointer;
  }
}
</style>